/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package generators;
import java.io.*;
import java.util.*;
import simframe.util.Bucket;
/**
 *
 * @author Isaac Noble
 */
public class FileMerger
{
    public static void main(String args[]) throws IOException
    {
        Bucket<String> lines = new Bucket<String>();
        File dir = new File("C:\\sim_works");
        File[] files = dir.listFiles();
        for(int i = 0; i < files.length; i++)
        {
            if(files[i].getName().indexOf("agent") > 0)
            {
                FileReader in = new FileReader(files[i]);
                BufferedReader reader = new BufferedReader(in);

                String line;
                while ((line = reader.readLine()) != null) {
                    lines.add(line);
                }
            }
        }

        File out_file = new File(dir.getPath() + "\\random_merge.txt");
        FileWriter out = new FileWriter(out_file);
        BufferedWriter writer = new BufferedWriter(out);

        Iterator<String> iter = lines.iterator();
        while(iter.hasNext())
        {
            writer.write(iter.next());
            writer.newLine();
        }
        writer.close();
        out.close();
    }
}
